package com.ruoyi.car.business.web.controller;

import com.ruoyi.car.business.domain.BusStatement;
import com.ruoyi.car.business.query.StatementQuery;
import com.ruoyi.car.business.service.IBusStatementService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TablePageInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 结算单Controller
 * 
 * @author ruoyi
 * @date 2022-01-27
 */
@Controller
@RequestMapping("/business/statement")
public class BusStatementController extends BaseController
{
    private String prefix = "business/statement";

    @Autowired
    private IBusStatementService busStatementService;

    @RequiresPermissions("business:statement:view")
    @GetMapping("/listPage")
    public String statement()
    {
        return prefix + "/statement";
    }

    /**
     * 查询结算单列表
     */
    @RequiresPermissions("business:statement:list")
    @PostMapping("/list")
    @ResponseBody
    public TablePageInfo<BusStatement> query(StatementQuery qo){
        return busStatementService.query(qo);
    }

    /**
     * 导出结算单列表
     */
    @RequiresPermissions("business:statement:export")
    @Log(title = "结算单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BusStatement busStatement)
    {
        List<BusStatement> list = busStatementService.selectBusStatementList(busStatement);
        ExcelUtil<BusStatement> util = new ExcelUtil<BusStatement>(BusStatement.class);
        return util.exportExcel(list, "结算单数据");
    }

    /**
     * 新增结算单
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存结算单
     */
    @RequiresPermissions("business:statement:add")
    @Log(title = "结算单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BusStatement busStatement)
    {
        return toAjax(busStatementService.insertBusStatement(busStatement));
    }

    /**
     * 修改结算单
     */
    @RequiresPermissions("business:statement:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        BusStatement busStatement = busStatementService.selectBusStatementById(id);
        mmap.put("busStatement", busStatement);
        return prefix + "/edit";
    }

    /**
     * 修改保存结算单
     */
    @RequiresPermissions("business:statement:edit")
    @Log(title = "结算单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BusStatement busStatement)
    {
        return toAjax(busStatementService.updateBusStatement(busStatement));
    }

    /**
     * 删除结算单
     */
    @RequiresPermissions("business:statement:remove")
    @Log(title = "结算单", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(Long id)
    {
        return toAjax(busStatementService.deleteBusStatementById(id));
    }
}
